/**
 * Created by leiweibo on 7/25/15.
 */

var app = angular.module('feeservice', []);
app.factory('FeeService', function($http, BaseService) {
  return {
    create: function(data, success, error) {
      $http.post(BaseService.baseUrl + '/patient_fee/create', data).success(success).error(error);
    },
    update: function(data, success, error) {
      $http.put(BaseService.baseUrl + '/patient_fee/update', data).success(success).error(error);
    },
    delete: function(data, success, error) {
      $http.delete(BaseService.baseUrl + '/patient_fee/delete?id=' + data.id).success(success).error(error);
    },
    list: function(pageNo, pageSize, params, success) {
      var filterCondition = params.search.predicateObject;
      var queryStr = '';
      if (filterCondition) { //TODO
        if (filterCondition.username) {
          queryStr += ('&username=' + filterCondition.username);
        }

        if (filterCondition.realname) {
          queryStr += ('&realname=' + filterCondition.realname);
        }
      }

      //if (province) {
      //  queryStr += ('&province=' + province);
      //}
      //if (hospital) {
      //  queryStr += ('&hospital=' + hospital);
      //}
      $http.get(BaseService.baseUrl + "/patient_fee/list?pageNo=" + pageNo + "&pageSize=" + pageSize + queryStr)
        .success(success);
    }

  }
}).factory('FeeData', function() {
  var savedData = {};
  function set(data) {
    savedData = data;
  }

  function get() {
    return savedData
  }

  return {
    get: get,
    set: set
  }
});
